package cn.wolfcode.wolf2w.controller;


import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Banner;
import cn.wolfcode.wolf2w.domain.Strategy;
import cn.wolfcode.wolf2w.domain.Travel;
import cn.wolfcode.wolf2w.query.BannerQueryObject;
import cn.wolfcode.wolf2w.service.*;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("banner")
public class BannerController {

    @Autowired
    private IBannerService BannerService;
    @Autowired
    private IDestinationService destinationService;
    @Autowired
    private IStrategyThemeService strategyThemeService;
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private ITravelService travelService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") BannerQueryObject qo) {
        Page<Banner> page = BannerService.query(qo);
        model.addAttribute("page", page);
        return "banner/list";
    }

    @RequestMapping("/listDests")
    @ResponseBody
    public Object listDests() {
        return destinationService.list();
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Banner Banner) {
        if (StringUtils.hasLength(Banner.getId())) {
            BannerService.update(Banner);

        } else {
            BannerService.save(Banner);

        }
        return JsonResult.success();
    }

    @RequestMapping("/getDestByDeep")
    @ResponseBody
    public Object getDestByDeep(int deep) {
        List<Destination> destinations = destinationService.getDestByDeep(deep);
        return destinations;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id) {
        BannerService.delete(id);
        return JsonResult.success();
    }

    @RequestMapping("/getAllType")
    @ResponseBody
    public Object getAllType() {
        Map<String, Object> map = new HashMap<>();
        List<Strategy> list = strategyService.list();
        List<Travel> l = travelService.list();
        map.put("sts", list);
        map.put("ts", l);
        return JsonResult.success(map);

    }


}
